package com.loop.unclelend.ui.fragment

import android.view.LayoutInflater
import android.view.View
import com.loop.unclelend.R
import com.loop.unclelend.databinding.UiPageHomeBinding
import com.loop.unclelend.pro.ProFragment
import com.loop.unclelend.ui.activity.Act_Main
import com.loop.unclelend.ui.activity.Act_Message
import com.loop.unclelend.ui.presenter.Pre_Home
import com.loop.unclelend.ui.view.IView_Home
import com.loop.unclelend.utils.event.UncleEventData

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/9 16:48
 * @Annotation：首页
 */
class Fm_Home: ProFragment(),IView_Home {
    lateinit var binding: UiPageHomeBinding
    var presenter: Pre_Home? = null

    //订单状态： 审核中 、 放款中 、 已拒绝
    private var loanStatusFm: Fm_Loan_Status? = null
    //额度信息: 未授信、未借款、已借款
    private var loanLimitFm: Fm_Loan_Limit? = null

    override fun getUncleRootView(inflater: LayoutInflater): View {
        binding = UiPageHomeBinding.inflate(inflater)
        return binding.root
    }

    override fun initUncleView() {
        setUncleTitleBarVisibility(View.VISIBLE)
        //拦截返回
        isInterceptBack(true)
        setUncleBackBtnRes(R.mipmap.icon_menu)
        setUncleRightBtnRes(R.mipmap.icon_message)
    }

    override fun initUncleListener() {
        rootViewBinding.imgBack.setOnClickListener {
            val act = getAct() as Act_Main
            act.showUncleMenuFragment("Home Page")
        }
        rootViewBinding.imgKefu.setOnClickListener {
            onIntent(Act_Message::class.java)
        }
    }

    override fun initUncleData() {
        presenter = Pre_Home(this)
        presenter!!.requestProcessAction()
    }

    override fun onUncleEvent(event: UncleEventData) {
        super.onUncleEvent(event)
        when(event.eventType){
            UncleEventData.TYPE.UNCLE_PROCESS_REFRESH -> {//刷新总流程
                presenter!!.requestProcessAction()
            }
            else -> {

            }
        }
    }

    /**
     * 隐藏所有页面
     */
    override fun hideUncleAllPages() {
        if (loanLimitFm != null){
            getAct().hideContainerFragement(loanLimitFm)
        }
        if (loanStatusFm != null){
            getAct().hideContainerFragement(loanStatusFm)
        }
    }

    /**
     * 显示订单状态： 审核中 、 放款中 、 已拒绝
     */
    override fun showUncleOrderStatusView() {
        if (loanStatusFm == null){
            loanStatusFm = Fm_Loan_Status()
        }
        if (loanStatusFm!!.isAdded){
            getAct().showContainerFragement(loanStatusFm)
        } else {
            getAct().addContainerFragement(R.id.layout_home,loanStatusFm)
        }
    }

    /**
     * 显示贷款额度信息： 未授信、未借款、已借款
     */
    override fun showUncleLoanLimitView() {
        if (loanLimitFm == null){
            loanLimitFm = Fm_Loan_Limit()
        }
        if (loanLimitFm!!.isAdded){
            getAct().showContainerFragement(loanLimitFm)
        } else {
            getAct().addContainerFragement(R.id.layout_home,loanLimitFm)
        }
    }
}